import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/Login/login-index.vue'
import Layout from '@/views/Layout/layout-index.vue'
import Home from '@/views/Home/home-index.vue'
import Category from '@/views/Category/category-index.vue'
import subCategory from '@/views/subCategory/subCategory.vue'
import detialIndex from '@/views/Detail/detail-index.vue'
import cartListIndex from '@/views/CartList/cartList-index.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  // path和component对应关系的位置
  routes: [
    {
      path: '/',
      component: Layout,
      children: [
        {
          path: '',
          component: Home
        },
        {
          path: 'category/:id',
          component: Category,
        },
        {
          path: 'category/sub/:id',
          component: subCategory,
        },
        {
          path: 'detail/:id',
          component: detialIndex
        },
        {
          path:'cartlist',
          component:cartListIndex
        }
      ]
    },
    {
      path: '/login',
      component: Login
    }
  ],
  //路由行为的配置项
  scrollBehavior(){
    return{top:0}
  }
})

export default router
